function xstar = findinterp(xgrid,ygrid,interp_type)
%find x*, where f(x*)=0; f(x)=y at each gridpoint
%Uses interp_type for interpolation between gridpoints
%Assumes single crossing of 0

%Input: xgrid: 1 x nn vector of x values
%       ygrid: 1 x nn vector of y values
%       interp_type: 'linear', 'linear*' (equidistant linear: fast), 'cubic'

%Output xstar: scalar of point where f(x*) = 0

nn = length(xgrid);

%First find the lowest grid point where the y grid crosses 0
xstarl_ind = find(or(and(ygrid(1:nn-1)>0,ygrid(2:nn)<0),and(ygrid(1:nn-1)<0,ygrid(2:nn)>0)),1);

xstar = fzero(@finterp,[xgrid(xstarl_ind) xgrid(xstarl_ind+1)]);

 function y = finterp(x)
   y = interp1(xgrid,ygrid,x,interp_type);  
 end


end

